package com.cn.pack.service;

import com.cn.pack.config.HystrixThreadLocal;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

@Service
public class ThreadContextService {

    @HystrixCommand
    public String getUser(String id) {
        System.out.println("---------------- current thread : " + Thread.currentThread().getId());
        System.out.println("---------------- thread local: " + HystrixThreadLocal.threadLocal.get());
        System.out.println("---------------- requestContextHolder : " + RequestContextHolder.currentRequestAttributes().getAttribute("userId", RequestAttributes.SCOPE_REQUEST));

        return id;
    }
}
